package com.css.bjdt_report.report.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.nutz.dao.sql.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.css.bjdt_report.report.entity.RptTemplateStatCategory;
import com.css.bjdt_report.report.service.ReportStatCategoryService;
import com.css.bjdt_report.util.PropertyFilter;

@Controller
@RequestMapping(value = "/reportStatCategoryController")
public class ReportStatCategoryController {

	@Autowired
	private ReportStatCategoryService reportStatCategoryService;

	//跳转到查询页面
	@RequestMapping("/reportStatCategoryInfolist")
	public String list(Model model) {
		return "/report-stat-category/report-stat-category-list";
	}

	@ResponseBody
	@RequestMapping("/tableData")
	public Map tableData(HttpServletRequest request, @RequestParam(value = "pageNum") int pageNum,
			@RequestParam(value = "pageSize") int pageSize) {
		Criteria cnd = PropertyFilter.cri(request);
		return reportStatCategoryService.queryPage(cnd, pageNum, pageSize);
	}

	//跳转到新增页面
	@RequestMapping("/toReportStatCategoryInfoInsert")
	public String toReportStatCategoryInfoInsert(Model model) {
		return "/report-stat-category/report-stat-category-input";
	}

	@RequestMapping(value = "/insertReportStatCategory")
	public String insertReportStatCategory(RptTemplateStatCategory record, Model model) {
		reportStatCategoryService.saveReportStatCategory(record);
		model.addAttribute("message", "操作成功");
		return "/report-stat-category/report-stat-category-input";
	}

	@ResponseBody
	@RequestMapping(value = "/deleteReportStatCategory/{id}")
	public String deleteReportStatCategory(@PathVariable String id) {
		try {
			reportStatCategoryService.deleteAReportStatCategoryById(id);
			return "success";
		} catch (Exception e) {
			e.getMessage();
			return "false";
		}
	}

	@RequestMapping("/toReportStatCategoryInfoUpdate/{id}")
	public String toReportStatCategoryInfoUpdate(@PathVariable String id, Model model) {
		model.addAttribute("rptTemplateStatCategory", reportStatCategoryService.getAReportStatCategoryById(id));
		return "/report-stat-category/report-stat-category-input";
	}

	@RequestMapping("/updateReportStatCategory")
	public String updateReportStatCategory(RptTemplateStatCategory record, Model model) {
		reportStatCategoryService.updateReportStatCategory(record);
		model.addAttribute("message", "操作成功");
		return "/report-stat-category/report-stat-category-input";
	}

	@ResponseBody
	@RequestMapping(value = "/getAllReportStatCategory")
	public List<RptTemplateStatCategory> getAllReportStatCategory() {
		return reportStatCategoryService.getAllReportStatCategory();
	}
}
